﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ExcelToOracle
{
    public partial class ConstantFieldsSettingDialog : Form
    {
        public ConstantValues Values { get; set; }

        public ConstantFieldsSettingDialog(ImportTemplate template)
        {
            InitializeComponent();

            Values = new ConstantValues();
            foreach (FieldTplt field in template.Constants)
            {
                Values.Values.Add(new ConstantValue(field, string.Empty));
            }

            foreach (ConstantValue value in Values.Values)
            {
                if (value.Field.Type == "guid")
                {
                    int index = dataGridView1.Rows.Add(value.Field.TableColumn, value.Field.Type);
                    dataGridView1.Rows[index].Tag = value;
                    dataGridView1.Rows[index].Cells[1].ReadOnly = true;
                }
                else if (value.Field.Type == "mapping")
                {
                    int index = dataGridView1.Rows.Add(value.Field.TableColumn, value.Field.Type + "(" + value.Field.TypeData + ")");
                    dataGridView1.Rows[index].Tag = value;
                    dataGridView1.Rows[index].Cells[1].ReadOnly = true;
                }
                else
                {
                    int index = dataGridView1.Rows.Add(value.Field.TableColumn, value.Value);
                    dataGridView1.Rows[index].Tag = value;
                }
            }
        }

        private void dataGridView1_CellEndEdit(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow row = dataGridView1.Rows[e.RowIndex];
            ConstantValue value = row.Tag as ConstantValue;
            value.Value = Convert.ToString(row.Cells[e.ColumnIndex].Value);
        }

        private void _btnOK_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("常量设置是否已完成?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.OK)
            {
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
